<?php
// 分销订单表
namespace app\shop\model;

use think\Model;
use think\Request;

class MemberDistributionOrder extends Model
{

    /*
     * 分销订单和会员订单一对一 (适用于我的分销->分销商(已产生佣金))
     */
    public function memberOrder()
    {
        //确认收货和已完结的订单  状态为3,4
        return $this->hasOne('MemberOrder','shop_order_number','order_number')->where(['status' => ['in', '3,4' ]])->field('id,status,shop_order_number,pay_time,price,freight');
    }
    /*
     * 分销订单和会员订单一对一 (适用于我的分销->分销商(未产生佣金))
     */
    public function memberOrderNot()
    {
        return $this->hasOne('MemberOrder','shop_order_number','order_number')->field('id,status,shop_order_number,pay_time');
    }
    public function getCreateTimeAttr($value)
    {
        return date('Y-m-d',$value);
    }

    /*
     * 分销订单和会员订单一对一 (适用于我的分销->分销订单)
     */
    public function memberOrderList()
    {
        return $this->hasOne('MemberOrder','shop_order_number','order_number');
    }
    /*
     * 分销订单和分销商( 推荐人 )多对一
     */
    public function memberDistribution()
    {
        return $this->belongsTo('MemberDistribution','member_id','referrals_id');
    }
    /*
     * 分销订单和会员表多对一
     */
    public function member()
    {
        return $this->belongsTo('Member','member_id','id');
    }

}
